package com.xjy.web.controller.system;

import com.xjy.common.annotation.Log;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.enums.BusinessType;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.SysFundaccountAddBo;
import com.xjy.system.domain.bo.SysFundaccountEditBo;
import com.xjy.system.domain.bo.SysFundaccountQueryBo;
import com.xjy.system.domain.vo.SysFundaccountVo;
import com.xjy.system.service.ISysFundaccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 资金账户信息Controller
 *
 * @author xjy
 * @date 2022-03-10
 */
@Api(value = "资金账户信息控制器", tags = {"资金账户信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/fundaccount")
public class SysFundaccountController extends BaseController {

	private final ISysFundaccountService iSysFundaccountService;

	/**
	 * 查询资金账户信息列表
	 */
	@ApiOperation("查询资金账户信息列表")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:list')")
	@GetMapping("/list")
	public TableDataInfo<SysFundaccountVo> list(@Validated SysFundaccountQueryBo bo) {
		return iSysFundaccountService.queryPageList(bo);
	}

	/**
	 * 查询资金账户信息列表
	 */
	@ApiOperation("查询资金账户信息列表")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:list')")
	@GetMapping("/selectList")
	public List<SysFundaccountVo> selectList(@Validated SysFundaccountQueryBo bo) {
		bo.setAuditStatus(true);
		return iSysFundaccountService.queryList(bo);
	}

	/**
	 * 导出资金账户信息列表
	 */
	@ApiOperation("导出资金账户信息列表")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:export')")
	@Log(title = "资金账户信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysFundaccountVo> export(@Validated SysFundaccountQueryBo bo) {
		List<SysFundaccountVo> list = iSysFundaccountService.queryList(bo);
		ExcelUtil<SysFundaccountVo> util = new ExcelUtil<SysFundaccountVo>(SysFundaccountVo.class);
		return util.exportExcel(list, "资金账户信息");
	}

	/**
	 * 获取资金账户信息详细信息
	 */
	@ApiOperation("获取资金账户信息详细信息")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysFundaccountVo> getInfo(@NotNull(message = "主键不能为空")
												@PathVariable("id") Long id) {
		return AjaxResult.success(iSysFundaccountService.queryById(id));
	}

	/**
	 * 新增资金账户信息
	 */
	@ApiOperation("新增资金账户信息")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:add')")
	@Log(title = "资金账户信息", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody SysFundaccountAddBo bo) {
		return toAjax(iSysFundaccountService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改资金账户信息
	 */
	@ApiOperation("修改资金账户信息")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:edit')")
	@Log(title = "资金账户信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/edit")
	public AjaxResult<Void> edit(@Validated @RequestBody SysFundaccountEditBo bo) {
		return toAjax(iSysFundaccountService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 修改资金账户信息
	 */
	@ApiOperation("修改资金账户信息")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:edit')")
	@Log(title = "资金账户信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public AjaxResult<Void> audit(@Validated @RequestBody SysFundaccountEditBo bo) {
		return toAjax(iSysFundaccountService.auditByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除资金账户信息
	 */
	@ApiOperation("删除资金账户信息")
	@PreAuthorize("@ss.hasPermi('system:fundaccount:remove')")
	@Log(title = "资金账户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysFundaccountService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
